﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Lastfm.Services;
namespace LastFmDemo
{
    public partial class LogInForm : Form
    {
        User user;

        public User User
        {
            get { return user; }
            set { user = value; }
        }
        static String API_KEY = "d10c3c47d071f9208bb1500ac5ae3e6c";
        static String SECRET = "1225dd072c6b2c5da0079b17edc10385";
        public Session session;
        public LogInForm()
        {
            InitializeComponent();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (tbPass.Text.Trim()=="" || tbUsrname.Text.Trim()=="")
                return;
            
            if (Helper.LogIn(tbUsrname.Text, tbPass.Text, session))
            {
                user = new User(tbUsrname.Text, session);
                MainForm mf = new MainForm(this);
                this.Hide();
                mf.Show();
            }
            else
                MessageBox.Show("Login failed");
        }

        private void LogInForm_Load(object sender, EventArgs e)
        {
            session = new Session(API_KEY, SECRET);
            this.AcceptButton = button1;
        }
       
    }
}
